package com.atguigu.controller;

import com.atguigu.entity.BaseBrand;
import com.atguigu.entity.BaseCategoryView;
import com.atguigu.entity.ProductSalePropertyKey;
import com.atguigu.entity.SkuInfo;
import com.atguigu.service.BaseBrandService;
import com.atguigu.service.BaseCategoryViewService;
import com.atguigu.service.SkuDetailService;
import com.atguigu.service.SkuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sku/")
public class SkuDetailController {
    @Autowired
    private SkuDetailService skuDetailService;
    @Autowired
    private SkuInfoService skuInfoService;
    @Autowired
    private BaseCategoryViewService categoryViewService;
    @Autowired
    BaseBrandService baseBrandService;


    //1.根据skuid获取sku的基本信息(skuInfo)
    @GetMapping("getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable Long skuId){
        return skuDetailService.getSkuInfo(skuId);
    }
    //2.根据productId,skuId查询商品销售属性key与value
    @GetMapping("getSkuSalePropertyKeyAndValue/{productId}/{skuId}")
    public List<ProductSalePropertyKey> getSkuSalePropertyKeyAndValue(@PathVariable long productId, @PathVariable long skuId){
        return skuDetailService.getSkuSalePropertyKeyAndValue(productId,skuId);
    }
    //3.根据skuId 查询商品的价格
    @GetMapping("getSkuPrice/{skuId}")
    public BigDecimal getSkuPrice(@PathVariable long skuId){
        SkuInfo skuInfo = skuInfoService.getById(skuId);
        return skuInfo.getPrice();
    }
    //4.根据skuid获取sku的分类信息
    //通过视图实现
    @GetMapping("getCategoryView/{skuId}")
    public BaseCategoryView getCategoryView(@PathVariable Long skuId){
        return categoryViewService.getById(skuId);

    }
    //5.根据spuId获取该spu所对应的所有sku的销售属性值与sku的对应关系
    @GetMapping("getSkuSalePropertyValueIdMapping/{productId}")
    public Map getSkuSalePropertyValueIdMapping(@PathVariable Long productId){
        return skuDetailService.getSkuSalePropertyValueIdMapping(productId);
    }
    //通过brandID查询品牌信息
    @GetMapping("getBrandById/{brandId}")
    public BaseBrand getBrandById(@PathVariable Long brandId){
        return baseBrandService.getById(brandId);
    }
}
